package com.hy.erp.inventory.service;

import java.util.List ;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

/*import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;
*/
import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.ContactTypeDao;
import com.hy.erp.inventory.dao.PositionDao;
import com.hy.erp.inventory.dao.interfaces.IContactTypeDao;
import com.hy.erp.inventory.pojo.ContactType;
import com.hy.erp.inventory.pojo.interfaces.IContactType;
import com.hy.erp.inventory.service.interfaces.IContactTypeService;
/**
 * 
 * <ul>
 * <li>开发作者：李冰</li>
 * <li>设计日期：2010-10-13；时间：上午09:17:34</li>
 * <li>类型名称：ContactTypeService</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
/*@ Name ( "contactTypeService" )
@ Scope ( ScopeType.STATELESS )
@ Stateless*/
@Component("contactTypeService")
public class ContactTypeService extends AbstractBusinessService < ContactTypeDao > implements IContactTypeService{

	/**
	 * 
	 */
	private static final long serialVersionUID = 509733568944426548L;

	private ContactTypeDao contactTypeDao=null;
	

	@Resource(name="contactTypeDao")
	public void setContactTypeDao(ContactTypeDao contactTypeDao) {
		this.contactTypeDao = contactTypeDao;
	}
	@Override
	public boolean addContactType(ContactType contactType) {


		if ( null == contactType)
		{
			return true ;
		}
		
		else
		{
			//System.out
			//		.println("ssssssssssssssssssssssffffffffffffffffhghhhhhhhhhhhhhhhhhhhhhh");

			//IContactTypeDao contactTypeDao = (IContactTypeDao) this
			//		.getDao(IContactType.class);

			return contactTypeDao.persist(contactType);
		}
		
	
	
	}

	@Override
	public boolean modifyContactType(ContactType contactType) {


		if ( ( null == contactType )
			     || ( null == contactType
			                                .getIdentifier ( ) )
			     || ( contactType
			                        .getIdentifier ( )
			                        .trim ( )
			                        .length ( ) == 0 ) )
			{
				return true ;
			}
			else
			{

				//IContactTypeDao contactTypeDao =
               //     ( IContactTypeDao ) this
               //                        .getDao ( IContactType.class ) ;

		
					
				if ( null == contactType )
				{
					throw new ArchitectureFoundationException  (
					                                            "修改实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
				}
				
				
				return (contactTypeDao
				                  .merge ( contactType ) != null ) ;
			}
		
	
	
	}

	@Override
	public Integer removeContactType(String[] contactTypeIds) {


		if ( ( null == contactTypeIds)
			     || ( contactTypeIds.length == 0 ) )
			{
				return new Integer (
				                     0 ) ;
			}
			else
			{


				//IContactTypeDao contactTypeDao =
               //     ( IContactTypeDao ) this
               //                        .getDao ( IContactType.class ) ;

				return contactTypeDao
				                .remove ( contactTypeIds ) ;
			}
	
	
	}

	@ Override
	public String [ ] addContactType (
										Object [ ] contactType )
	{

		if ( null == contactType)
		{
			return null ;
		}
		
		else
		{
		

			//IContactTypeDao contactTypeDao =
			//                       ( IContactTypeDao ) this
			//                                          .getDao ( IContactType.class ) ;

			ContactType[] contactTypes=new ContactType[contactType.length];
						for(int i=0;i<contactType.length;i++)
						{
							ContactType contactType2=( ContactType ) contactType[i];
							contactTypes[i]=contactType2;
						}
						return contactTypeDao
						                .persist ( contactTypes ) ;
			
		
		}
		
	
	}

	@ Override
	public List < ContactType > getAllContactType ( )
	{
		///IContactTypeDao contactTypeDao =
         //   ( IContactTypeDao ) this
         //                      .getDao ( IContactType.class ) ;

		return contactTypeDao
		                .find ( ) ;
	}

	@ Override
	public String [ ] modifyContactType (
											Object [ ] contactType )
	{


		if ( null == contactType)
		{
			return null ;
		}
		
		else
		{
		

		///	IContactTypeDao contactTypeDao =
		//	                       ( IContactTypeDao ) this
		//	                                          .getDao ( IContactType.class ) ;

			ContactType[] contactTypes=new ContactType[contactType.length];
						for(int i=0;i<contactType.length;i++)
						{
							ContactType contactType2=( ContactType ) contactType[i];
							contactTypes[i]=contactType2;
						}
						return contactTypeDao
						                .merge   ( contactTypes ) ;
			
		
		}
		
	
	
	}
	@ Override
	public List < ContactType > getContactTypeByName (
														String queryString )
	{
		if(queryString!=null)
		{
			//IContactTypeDao dao=( IContactTypeDao ) this.getDao ( IContactType.class );
			return contactTypeDao.find ( queryString );
		}
		return null;
	}
	


}
